import { loginApi } from '@/api'
import { setToken } from '@/utils'
import { RootThunkAction } from '.'

// 基础模板
export type LoginType = {
  type: 'login/login'
  token: string
}

function loginAction(mobile: string, code: string): RootThunkAction {
  return async (dispatch) => {
    //请求数据
    const res = await loginApi(mobile, code)
    //保存token
    setToken(res.data.data.token)

    //保存token到redux中
    dispatch({
      type:'login/login',
      token:res.data.data.token
    })
  }
}

export { loginAction }
